<!--  -->
<template>
    <div class="button">
        <el-upload ref="uploadRef" :action="uploadUrl" :limit="1" :auto-upload="true" :show-file-list="false" :on-success="uploadSuccess">
            <el-button type="warning">上传</el-button>
        </el-upload>
    </div>
</template>

<script setup>
import { defineEmits, ref } from "vue"
import { ElMessage }        from "element-plus"

let uploadUrl = ref("/api/data/upload")
let emits     = defineEmits([ "uploadSuccess" ])
let uploadRef = ref(null)

function uploadSuccess(response){
    ElMessage.success("上传成功")
    emits("uploadSuccess", response)

    if(uploadRef.value){
        uploadRef.value.clearFiles()
    }
}
</script>

<style lang="scss" scoped>
:deep(.el-upload) {
    width: 100%;

    .el-button {
        width: 100%;
    }
}
</style>
